//
// ScheduleObject.h
// Usage: Schedule unit for newlife
// CreateDate: 2009-04-20
// Author: MaJiuyue CaiRuicheng
//
#ifndef _SCHEDULEOBJECT_H_
#define _SCHEDULEOBJECT_H_

#include <type.h>
#include "Thread.h"
#include <LinkedList.h>
#include <bootutil.h>

/* Process status */
enum PROCESS_STATUS { PS_CREATING=0, PS_RUNNING, PS_READY, PS_BLOCKED, PS_DEAD };

class ScheduleObject
{
private:
	int tick;

protected:
	virtual int GetInitialTick() = 0;

public:
	ScheduleObject() { tick = 3; }
	virtual pid_t GetPID() = 0;
	virtual int GetPriority()=0;
	virtual void ResetTick(int priority) = 0;	
	virtual void Restart() = 0;
	virtual Thread * GetThread()=0;
	virtual void SwitchContext() = 0;
	virtual void SetPriority(int priority) = 0;
	virtual PROCESS_STATUS GetProcessStatus() = 0;
	virtual bool GoOn()
	{
		tick --;
		if(tick<0)
		{
			tick = GetInitialTick();
			return false;
		}
		return true;
	}
};

#endif

